fix: validate k shape when dims is omitted - #14329
Closed
Planeshifter wants to merge 1 commit into
Closed
Conversation
…itted
The job `Node.js v16` on workflow `macos_test` failed on develop with
6 tape assertion failures under "throws an error if provided a `k`
argument which is not broadcast-compatible": `circshift( x, k )` and
`circshift( x, k, {} )` did not throw for `k` shapes `[4]`, `[2,2,2]`,
and `[0]` against a `[2,2]` input, contrary to the documented
contract. Root cause: in `lib/main.js`, the no-`dims` branches for an
ndarray-valued `k` (`k_ndarray` in both the 2-argument and options-
argument call forms) passed `k` straight through to `base()` without
validating that its shape is broadcast-compatible with the implied
zero-dimensional target shape, unlike the `dims`-provided branch,
which already validates via `maybeBroadcastArray`. This commit applies
the same `maybeBroadcastArray( k, [] )` validation to both no-`dims`
branches, matching the idiom already used elsewhere in the codebase
(e.g. `@stdlib/blas/ext/copy-within/lib/broadcast_index.js`) and
restoring the documented `@throws` contract without changing behavior
for already-valid inputs (a 0-dimensional `k` continues to pass
through `maybeBroadcastArray` unchanged).
Ref: https://github.com/stdlib-js/stdlib/actions/runs/31938255523
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
Planeshifter
marked this pull request as ready for review
August 16, 2026 18:09
k shape when dims is omittedk shape when dims is omitted
Member
|
This is a duplicate. |
Member
Author
|
Confirmed — #14228 already covers this exact fix for Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request:
kargument againstmaybeBroadcastArray( k, [] )in the twocircshiftcode paths that omit thedimsoption, matching the validation already applied in thedims-provided path.Failing run: https://github.com/stdlib-js/stdlib/actions/runs/31938255523 (job
Node.js v16on workflowmacos_test; see raw logs)Symptom:
circshift( x, k )andcircshift( x, k, {} )did not throw for akshape that is not broadcast-compatible with the implied zero-dimensional target (e.g.kshape[4],[2,2,2], or[0]againstxshape[2,2]), contrary to the documented contract.Root cause: the no-
dimsbranches for an ndarraykpassed it straight through tobase()unvalidated. In practice this was worse than a missing throw: an incompatibleksilently no-op'd (returnedxunmodified, ignoringkentirely) rather than either shifting correctly or raising an error.Related Issues
This pull request has the following related issues:
Questions
No.
Other
Validated by three independent reviewers (correctness, regression scope, style/conventions); all approved. Reviewer B ran the package's full test suite directly (270/270 passing, including the two previously-failing blocks). No fan-out:
circshiftis a leaf package with no in-repo callers passing an ndarrayk.Checklist
Please ensure the following tasks are completed before submitting this pull request.
AI Assistance
Yes
No
Code generation (e.g., when writing an implementation or fixing a bug)
Test/benchmark generation
Documentation (including examples)
Research and understanding
Disclosure
This PR was proposed by Claude Code as part of an automated CI-failure investigation routine. The root-cause analysis, the fix, and three-reviewer validation (correctness, regression scope, style/conventions) were produced by Claude Code. Final review and merge decision rest with the maintainers.
@stdlib-js/reviewers
Generated by Claude Code